const http = require("http");
const path = require("path"); // 处理路径相关
const fs = require("fs"); // 操作文件

const server = http.createServer((req, res) => {
  fs.readFile(
    path.resolve(__dirname, "./demo.html"),
    "utf-8",
    (error, result) => {
      // error 错误信息，如果不为null，代表当前读取文件出错
      // result 读取到的内容
      console.log(result);

      res.end(result);
    }
  );
});

server.listen(3000, () => {
  console.log("服务启动成功");
});
